<template>
  <el-container class="layout-container-demo" style="height: 500px">
    <el-aside width="200px">
      <el-scrollbar>
        <el-menu :default-openeds="['1', '3']">
          <h1
            :style="{height: '110px', textAlign: 'center', lineHeight: '110px', color: '#1ba9ba', fontFamily: 'cursive'}"
          >八维票务</h1>
          <div
            v-for="(item, index) in children"
            @click="routerLink(item.path as string, index)"
            :key="index"
            :to="item.path"
          >
            <el-menu-item :index="1 + index">
              <template #title>
                <el-icon>
                  <img
                    style="width: 30px; height: 30px;"
                    :src="item.meta.img[index === current ? 1 : 0]"
                  />
                </el-icon>
                <span :id="index === current ? 'active' : ''">{{ item.meta.title }}</span>
              </template>
            </el-menu-item>
          </div>
        </el-menu>
      </el-scrollbar>
    </el-aside>

    <el-container>
      <el-header style="text-align: right; font-size: 12px">
        <div class="toolbar">
          <el-dropdown>
            <el-icon style="margin-right: 8px; margin-top: 1px">
              <setting />
            </el-icon>
            <template #dropdown>
              <el-dropdown-menu>
                <el-dropdown-item>View</el-dropdown-item>
                <el-dropdown-item>Add</el-dropdown-item>
                <el-dropdown-item>Delete</el-dropdown-item>
              </el-dropdown-menu>
            </template>
          </el-dropdown>
          <span>Tom</span>
        </div>
      </el-header>

      <el-main>
        <el-scrollbar>
          <router-view></router-view>
        </el-scrollbar>
      </el-main>
    </el-container>
  </el-container>
</template>

<script lang="ts" setup>
type routerLink = (path: string, index: number) => void;
import { ref, onMounted } from "vue";
import router, { children } from "../router";
import { Menu as IconMenu, Message, Setting } from "@element-plus/icons-vue";

let current = ref(0);

const routerLink: routerLink = (path, index) => {
  // console.log(path, index);
  current.value = index;
  router.push({ path });
};

onMounted((): void => {
  getCurrent()
})

const getCurrent = (): void => {
  let path: string = location.pathname
  // console.log(path)
  let index: number = children.findIndex((item: any) => item.path === path)

  current.value = index
}
</script>

<style scoped>
html,
body,
#app,
.layout-container-demo {
  width: 100vw;
  height: 100vh;
}
.layout-container-demo .el-header {
  position: relative;
  /* background-color: var(--el-color-primary-light-7); */
  box-shadow: 0vw 0vw 1vw 0vw rgba(51, 51, 51, 0.1);
  color: var(--el-text-color-primary);
}
.layout-container-demo .el-aside {
  height: 100vh !important;
  color: var(--el-text-color-primary);
  /* background: var(--el-color-primary-light-8); */
  box-shadow: 0vw 0vw 1vw 0vw rgba(51, 51, 51, 0.1);
}
.layout-container-demo .el-menu {
  border-right: none;
}

.layout-container-demo .is-vertical {
  height: 100vh !important;
}
.layout-container-demo .el-main {
  /* margin: 3px; */
  height: 100% !important;
  background: #f1f1f1;
  /* background: #ccc; */
}
.layout-container-demo .toolbar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  right: 20px;
}

#active {
  color: #3bc9a9 !important;
}
</style>